home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0084_Adding Commas To Format.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  1KB  |  48 lines

  1. {
  2.  > says how big the file is it says it like 34443 and I was
  3.  > wondering
  4.  > is there a command or something I can add in TP6 to make it read
  5.  > 34,443 where it detects where to add a commas. I know there is
  6. }
  7. Program Comma;
  8.  
  9. Uses Crt;
  10.  
  11. Var x : longint;
  12.     Y : string;
  13.  
  14. Function CommaNum ( I : LongInt ) : String;
  15. Var
  16.     TmpString : String;
  17.     Counter, Tester : Byte;
  18. Begin
  19.   TmpString := '';
  20.   Counter   := 0;
  21.   Tester    := 0;
  22.   Str (i, TmpString);
  23.   For Counter := Length (TmpString) Downto 1 Do
  24.   Begin
  25.     Inc (Tester);
  26.     If Tester = 3 Then
  27.     Begin
  28.       Tester := 0;
  29.       Dec (Counter);
  30.       TmpString := Copy (TmpString, 1, Counter) + ','
  31.                  + Copy (TmpString, Counter + 1, Length (TmpString) );
  32.       Inc (Counter);
  33.     End;
  34.   End;
  35.   If TmpString[1] = ',' THEN DELETE(TmpString,1,1);
  36.   CommaNum := TmpString;
  37. End;
  38.  
  39. Begin
  40. ClrScr;
  41. Write('Enter a number ---> ');
  42. Readln(x);
  43. Y := COMMANUM(X);
  44. Write('Here it is with COMMAS! ---> ');
  45. Write(y);
  46. Readln;
  47. End.
  48.